package com.bsj.sipgateway.sip.transmit.request.impl;


import com.bsj.sipgateway.sip.transmit.request.SIPRequestAbstractProcessor;
import lombok.extern.slf4j.Slf4j;

import javax.sip.RequestEvent;
import javax.sip.ServerTransaction;
import javax.sip.header.ExpiresHeader;
import javax.sip.message.Request;
import javax.sip.message.Response;

/**    
 * @Description:SUBSCRIBE请求处理器
 * @author bsj-chenjunkang
 * @date 2022/8/24
 */
@Slf4j
public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor {

	/**   
	 * 处理SUBSCRIBE请求  
	 * 
	 * @param evt
	 */
	@Override
	public void process(RequestEvent evt) {
		Request request = evt.getRequest();

		try {
			Response response = null;
			response = getMessageFactory().createResponse(200, request);
			if (response != null) {
				ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30);
				response.setExpires(expireHeader);
			}
			//设置设备的外网端口
			setRport(evt, response);
			ServerTransaction transaction = getServerTransaction(evt);
			if (transaction != null) {
				transaction.sendResponse(response);
				transaction.terminate();
			} else {
				System.out.println("processRequest serverTransactionId is null.");
			}

		} catch (Exception e) {
			log.error("处理SUBSCRIBE请求异常", e);
		}
	}

}
